<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2022/8/16
  Time: 23:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>addRoom</title>
    <!-- 通过cdn的方式引入，需要连网 -->
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="${pageContext.request.contextPath}/static/js/vue.min.js" type="text/javascript"></script>
    <!-- 解决浏览器生产提示信息 -->
    <script> Vue.config.productionTip=false </script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入vue.js -->
    <script src="${pageContext.request.contextPath}/static/js/jquery-2.1.1.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="app">
        <el-form ref="form" :model="room" label-width="80px">
            <el-form-item label="房间类型">
                <el-input v-model="room.roomType"></el-input>
            </el-form-item>
            <el-form-item label="房间价格">
                <el-input v-model="room.roomPrice" type="number"></el-input>
            </el-form-item>
            <el-form-item label="房间状态">
                <el-input type="number" v-model="room.roomState"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="insertRoom">新增房间</el-button>
            </el-form-item>
        </el-form>
    </div>
<script>
    new Vue({
        el:'#app',
        data:{
            room:{
                roomType: "",
                roomPrice:"",
                roomState:""
            }
        },
        methods:{
            insertRoom(){
                console.log(this.room)
                var _this=this;
                $.ajax({
                    url:'${pageContext.request.contextPath}/room/insertRoom',
                    dataType:'json',
                    type:'post',
                    data: {
                        roomType:this.room.roomType,
                        roomPrice:this.room.roomPrice,
                        roomState:this.room.roomState
                    },
                    success:function (rs) {
                        if (rs.code == 200){
                            _this.$alert(rs.msg+",2秒之后回到用户列表")
                            setTimeout(function () {
                                location.href = '${pageContext.request.contextPath}/roomList';
                            })
                        }else {
                            _this.$alert(rs.msg)
                        }
                    }
                })
            }
        }
    })
</script>
</body>
</html>
